package com.xd.spring.liteflow.controller;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/if")
public class IfController {

    @Resource
    private FlowExecutor flowExecutor;

    @RequestMapping("/chain1")
    public Object chain1() {
        Map<String, Object> r = new HashMap<>();
        long start = System.currentTimeMillis();


        LiteflowResponse response = flowExecutor.execute2Resp("ifChain", "arg");


        long end = System.currentTimeMillis();
        long cost = (end - start) / 1000;
        r.put("code", response.getCode());
        r.put("message", response.getMessage());
        r.put("success", response.isSuccess());
        r.put("requestId", response.getRequestId());
        r.put("trace", response.getExecuteStepStrWithTime());
        r.put("cost", cost);
        return r;
    }
}
